<?php
// +----------------------------------------------------------------------
// | ThinkSNS
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.thinksns.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: nonant <nonant@thinksns.com>
// +----------------------------------------------------------------------
//

//用户空间信息修改页面
class InfoAction extends Action{

	var $_topmenu;
	function _initialize(){
		$arr = array(
			'baseinfo' => array('info' => L('nav_baseinfo'),'url'  => '__APP__&mod=Info&type=baseinfo'),
			'skill' => array('info' => L('nav_skill'),'url'  => '__APP__&mod=Info&type=skill'),
			'experience' => array('info' => L('nav_experience'),'url'  => '__APP__&mod=Info&type=experience'),
			//'organise' => array('info' => '架构体系','url'  => '__APP__&mod=info&type=organise'),
			'work' => array('info' => L('nav_work'),'url'  => '__APP__&mod=Info&type=work'),
			'userface' => array('info' => L('nav_headface'),'url'  => '__APP__&mod=Info&type=userface'),
		);
		$this->_topmenu = $arr;
		$this->assign('topmenu',$arr);
		

		$this->setTitle( L('base_title') );
	
		
	}

	function index(){
		$type = $_GET['type']?$_GET['type']:'baseinfo';
		if(in_array($type,array_keys($this->_topmenu))){
			$this->assign('type',$type);
			$this->$type();
		}else{
			$this->error( L('error_parameters') );
		}
	}



	//基本信息
	public function baseinfo(){

		if ($_POST){
			$pBaseInfo = D('BaseInfo');
			$hrbiInfo = $pBaseInfo->get_Hrbi_info( $this->user['uname'] );
			if( $hrbiInfo ){
				$list = $pBaseInfo ->get_Hrbi_Info_Data( $this->user['uname'] ,'baseinfo' );
				foreach($list as $key=>$value){
					$data[$key] = $value['value'];
				}
			}else{
				$data = $_POST['data'];
			}
			$a = D('Space')->save_Base_Data($this->mid,'baseinfo',$data,$_POST['index']);
			//$r=x('Notify')->put('space_upbaseinfo',$this->mid);
		}
		$userInfo = $this->user;
		$cardId =  $userInfo['uname'];
		$list = D('Space')->get_Base_Data($this->mid,'baseinfo');

		$this->assign('list',$list);
		$this->assign('space',D('Space')->get_Space_field($this->mid,'baseinfo'));
		$this->assign('isHrbi',D('BaseInfo')->get_Hrbi_info($cardId));
		$this->assign('cardId',$cardId);
		$this->display('baseinfo');
	}



	//从Hrbi上调取最新的基本信息
	public function getHrbiInfo(){
		echo exit(json_encode(D('BaseInfo')->get_Hrbi_Info_Data($_GET['cardId'])));
	}


	//项目经验
	public function experience(){
		if ($_POST){
			$r = D('Space')->save_Expend_Data($this->mid,'experience',$_POST['data'],$_POST['index']);
			//dump($r);
		}
		$info = D('Space')->get_Expend_Data($this->mid,'experience');
		$this->assign('info',$info);
		$this->assign('space',D('Space')->get_Space_field($this->mid,'extend'));
		$this->display('experience');
	}

	//组织架构
	public function organise(){
		if ($_POST){
			D('Space')->save_Expend_Data($this->mid,'organise',$_POST['data']);
		}
		$info = D('Space')->get_Expend_Data($this->mid,'organise');
		$this->assign('info',$info);
		//$this->assign('space',D('Space')->get_Space_field($this->mid,'projectexp'));
		$this->display('organise');
	}

	//擅长技能
	public function skill(){
		$list = D('SpaceTags')->doget($this->mid);
		$commendlist = D('SpaceTags')->getCommendList($this->mid);
		$this->assign('commendlist',$commendlist);
		$this->assign('list',$list);
		$this->display('skill');
	}

	public function doskill(){
		$strtype = $_POST['type'];
		if($strtype=='add'){  //添加
			echo D('SpaceTags')->doadd( $this->mid , h($_POST['tagname']) ) ;
		}elseif ($strtype=='del'){
			echo D('SpaceTags')->dodel( $this->mid , intval($_POST['tagid']) );
		}elseif ($strtype == 'addone'){
			echo D('SpaceTags')->doaddone( $this->mid , intval($_POST['tagId']) );
		}
	}

	//工作信息修改页
	public function work(){
		$list = D('Space')->get_ListInfo_Data($this->mid,'workinfo');
		$this->assign('list',$list);
		$this->display('work');
	}

	function dowork(){
		$strType = $_POST['type'];
		if($strType=='add'){
			$endtime = ($_POST['nowworkflag'])?'至今':$_POST['eyear'].'年'.$_POST['emonth'].'月';
			$time    = $_POST['byear'].'年'.$_POST['bmonth'].'月-'.$endtime;
			foreach ($_POST['data'] as $key=>$val){
				$_POST['data'][$key]['time'] = $time;
			}
			$old = D('Space')->get_ListInfo_Data($this->mid,'workinfo');
			if($old){
				$list = $old+$_POST['data'];
			}else{
				$list = $_POST['data'];
			}

			$r = D('Space')->save_ListInfo_Data($this->mid,'workinfo',$list);
			//dump($r);
			redirect('index.php?app=home&mod=info&type=work');
		}elseif ($strType=='del'){
			$list = D('Space')->get_ListInfo_Data($this->mid,'workinfo');
			unset($list[intval($_POST['id'])]);
			echo D('Space')->save_ListInfo_Data($this->mid,'workinfo',$list);
		}
	}

	//设置用户头像
	function userface(){
		$this->display('userface');
	}

	public function setAvatar(){
		$uid	=	$this->mid;
		$big	=	$_POST['big_avatar'];
		$small	=	$_POST['small_avatar'];
	}

	//帐号信息设置，为实现左侧菜单的统一~
	public function accountset(){
		$type = $_GET['type']?$_GET['type']:'feed';
		if(in_array($type,array('feed','notify','email'))){
			$this->assign('type',$type);
			$this->$type();
		}else{
			$this->error( L('error_parameters') );
		}
	}
	
	//动态设置
	public function feed(){
		if($_POST){
			$result = D('SpaceSetting')->save_User_Setting($this->mid,'feed',$_POST['data']) ;
		}
		$template = require SITE_PATH.'/public/language/'.getLang().'/feeds.php';
		foreach ($template  as $key=>$val){
			if($val['private']!=true){
				$app = explode('_',$key);
				$list[$app[0]][]  = array(
					'key' => $key,
					'info' => $val['info'],
				);
			}
		}
		
		//dump($list);
		$this->assign('list',$list);
		$this->assign('setting',D('SpaceSetting')->get_User_Setting($this->mid,'feed'));
		$this->display('feed');
	}


	//通知设置
	public function notify(){
		if($_POST){
			$result = D('SpaceSetting')->save_User_Setting($this->mid,'notify',$_POST['data']) ;
		}
		$template = require SITE_PATH.'/public/language/'.getLang().'/notifys.php';
		foreach ($template  as $key=>$val){
			$app = explode('_',$key);
			$list[$app[0]][]  = array(
				'key' => $key,
				'info' => $val['info'],
			);
		}

		$this->assign('list',$list);
		$this->assign('setting',D('SpaceSetting')->get_User_Setting($this->mid,'notify'));
		$this->display('notify');
	}

	//邮件设置
	public function email(){
		if($_POST){
			$result = D('SpaceSetting')->save_User_Setting($this->mid,'email',$_POST['data']) ;
		}
		$template = require SITE_PATH.'/public/language/'.getLang().'/notifys.php';
		foreach ($template  as $key=>$val){
			$app = explode('_',$key);
			$list[$app[0]][]  = array(
				'key' => $key,
				'info' => $val['info'],
			);
		}
		$this->assign('list',$list);
		$this->assign('setting',D('SpaceSetting')->get_User_Setting($this->mid,'email'));
		$this->display('email');
	}
}
?>